<template>
	<view>
		<view class="logo">
			<image class="logo-img" src="../../static/image/icon-logo.png"></image>
		</view>
		<view class="uni-common-mt">
			<view class="uni-form-item uni-column">
				<view class="title">用户名</view>
				<view class="with-fun">
					<input class="uni-input" placeholder="请输入用户名" :value="inputClearValue" @input="clearInput"/>
					<view class="uni-icon uni-icon-clear" v-if="showClearIcon" @click="clearIcon"></view>
				</view>
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">密码</view>
				<view class="with-fun">
					<input class="uni-input" placeholder="请输入密码" :value="inputPasswordValue" :password="showPassword"  @input="passwordInput"/>
					<view class="uni-icon uni-icon-eye" :class="[!showPassword ? 'uni-active' : '']" @click="changePassword"></view>
				</view>
			</view>
		</view>
		<view class="login-text">登录代表你已同意<text :style="{'color':'#38f'}" @tap="testClick">《隐私政策协议》</text></view>
		<view class="login-button">
			<button type="primary" :loading="loadingOff" @tap="handleLogin">登录</button>
		</view>
	</view>
</template>
<script>
	import login from '@/common/login.js'
	import {apiJavaLogin} from '@/common/api.js'
	export default {
		name:"login",
		data() {
			return {
				showClearIcon: false,
				inputClearValue: '',
				showPassword: true,
				loadingOff:false,
				inputPasswordValue:'',
				brand:'',
				model:''
			}
		},
		created(){
			let that=this
			uni.getSystemInfo({
			    success: function (res) {
					that.brand=res.brand
					that.model=res.model
			    }
			});
		},
		methods: {
			testClick(){
				uni.navigateTo({
					url:'/pages/agreement/agreement'
				})
			},
			clearInput: function(event) {
				this.inputClearValue = event.target.value;
				if (event.target.value.length > 0) {
					this.showClearIcon = true;
				} else {
					this.showClearIcon = false;
				}
			},
			clearIcon: function() {
				this.inputClearValue = '';
				this.showClearIcon = false;
			},
			changePassword: function() {
				this.showPassword = !this.showPassword
			},
			passwordInput (e) {
				this.inputPasswordValue = e.target.value
			},
			handleLogin () {
				const Version = uni.getStorageSync('Version')
				const cid=plus.push.getClientInfo().clientid
				this.loadingOff =  true
				let data={
					username:this.inputClearValue,
					password:this.inputPasswordValue,
					pcOrApp:'app',
					Version:Version,
					cid:cid,
					brand:this.brand,
					model:this.model
				}
				login.token(data).then(token=>{
					this.loadingOff =  false
					uni.setStorageSync('token',token)
					if(token){
						uni.showToast({
							title: '登录成功',
							mask: true,
							icon:"none",
							duration: 1500,
							success:()=>{
								setTimeout(()=>{
									uni.switchTab({
										url:'/pages/index/index'
									})
								},1000)
							}
						});
					}
				}).catch(err=>{
					this.loadingOff =  false
					uni.showToast({
						title: err.msg,
						icon:"none",
						mask: true,
						duration: 1500
					});
				})
			
			},
		}
	}
</script>

<style lang="scss" scoped>
	.title {
		padding: 0 25upx;
	}
	.logo {
		display: flex;
		align-items:center;
		justify-content: center;
		margin-top: 40upx;
		&-img{
			width: 320upx;
			height: 320upx;
		}
	}
	.login-button{
		padding: 40upx 70upx;
	}
	.login-text{
		width: 100%;
		padding-top:20upx; 
		text-align: center;
		color: #888;
		
	}
</style>
